﻿package net.wangit.adm.org;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.support.UnitInterceptor;
import net.wangit.user.org.Org;
import net.wangit.user.org.OrgFactory;
import net.wangit.util.Checker;
import net.wangit.view.unit.UnitComponent;

public class OrgRelationUI implements UnitInterceptor {

	public OrgRelationUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String oid = ac.getRequestParameter("orgid");
		if (Checker.isEmpty(oid)) {
			return "";
		} else {
			Org organization = OrgFactory.getOrg(oid);
			unit.setTitle((new StringBuilder(String
					.valueOf(((UnitComponent) unit).getTitle()))).append(" - ")
					.append(organization.getName()).append("(").append(oid)
					.append(")").toString());
			return unit.write(ac);
		}
	}
}
